package com.jm.bishe.service.Impl;

import com.jm.bishe.entity.Admin;
import com.jm.bishe.entity.Result;
import com.jm.bishe.entity.SuperAdmin;
import com.jm.bishe.mapper.SuperAdminMapper;
import com.jm.bishe.service.SuperAdminService;
import com.jm.bishe.utils.JwtTokenUtil;
import com.jm.bishe.utils.MD5Util;
import com.jm.bishe.utils.VoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
@Slf4j
public class SuperAdminServiceImpl implements SuperAdminService {


    @Autowired
    SuperAdminMapper superAdminMapper;

    @Override
    public Result login(String name, String passWord) {
        List<SuperAdmin> superAdmins = superAdminMapper.querySuperAdmin(name);
        if (superAdmins.size()!=0){
            SuperAdmin superAdmin = superAdmins.get(0);
            if (!VoUtil.allFieldIsNULL(superAdmin)){
                if (name.equals(superAdmin.getSuperAdminName())
                        && MD5Util.desEncrypt(passWord).equals(
                        MD5Util.reconvertMD5(superAdmin.getSuperAdminPassWord()))){
                    return Result.success("登录成功",JwtTokenUtil.getToken(String.valueOf(superAdmin.getSuperAdminId())));
                }
                return Result.falure(1009,"用户名或密码错误",null);
            }
            return Result.falure(1001,"未知错误,请联系管理员",null);
        }
        return Result.falure(2029,"没有该管理员",null);
    }




}
